<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller;

use app\api\model\Page as PageModel;
use think\response\Json;

/**
 * 页面控制器
 * Class Index
 * @package app\api\controller
 */
class Page extends Controller {
	/**
	 * 页面数据
	 * @param int|null $pageId 页面ID, 不传的话默认为首页
	 * @return Json
	 * @throws \app\common\exception\BaseException
	 * @throws \think\Exception
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 */
	public function detail(int $pageId = null): Json {
		// 页面数据
		$model = new PageModel;
		$pageData = $model->getPageData($pageId);
		return $this->renderSuccess(compact('pageData'));
	}
	public function getTime(): Json {
		$start = "9:00";
		$end = "22:00";
		$list = [];
		$time = strtotime(Date('Y-m-d'));
		$time2 = strtotime(Date('Y-m-d 9:00'));
		$time3 = strtotime(Date('Y-m-d 10:00'));

		$timeList = [];
		for ($i = 0; $i < 13; $i++) {

			$timeList[] = ['value' => Date('H:i', $time2) . '-' . Date('H:i', $time3), 'label' => Date('H:i', $time2) . '-' . Date('H:i', $time3)];
			$time2 += 3600;
			$time3 += 3600;

		}

		$timeList1 = [];

		$time2 = strtotime(Date('Y-m-d 9:00'));
		$time3 = strtotime(Date('Y-m-d 10:00'));
		$hour = Date('H');
		if ($hour < 9) {
			$timeList1 = $timeList;
		} else {
			for ($i = 0; $i < 13; $i++) {
				$hour1 = Date('H', $time2);
				if ($hour < $hour1) {
					$timeList1[] = ['value' => Date('H:i', $time2) . '-' . Date('H:i', $time3), 'label' => Date('H:i', $time2) . '-' . Date('H:i', $time3)];
				}

				$time2 += 3600;
				$time3 += 3600;

			}

		}

		for ($id = 0; $id < 4; $id++) {
			$date = Date('Y-m-d', $time);
			if ($id == 0) {
				$list[] = ['value' => $date, 'label' => '今天', 'children' => $timeList1];
			}
			if ($id == 1) {
				$list[] = ['value' => $date, 'label' => '明天', 'children' => $timeList];
			}
			if ($id == 2) {
				$list[] = ['value' => $date, 'label' => '后天', 'children' => $timeList];
			}
			if ($id == 3) {
				$list[] = ['value' => $date, 'label' => $date, 'children' => $timeList];
			}
			$time += 86400;
		}

		return $this->renderSuccess(compact('list'));
	}
}
